package com.projet.entity.monstre;

import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import com.project.Constants;
import com.projet.entity.IEntity;
import com.projet.entity.RenderComponent;

public class ComposantGraphiqueMonstre extends RenderComponent {
	
	SpriteSheet sprites, spriteNaissance;
	Animation naissance, mort, gauche,droite, haut, bas,action, spriteCourant, endormi;
	
	public static final int duration=130;
	public static final boolean horizontalScan=true;
	public static final boolean autoUpdate=false;
	public static final int decalageX=4;
	public static final int decalageY=6;
	public static final int imageX=29;
	public static final int imageY=33;
	boolean naitre=true,reveil=true;
	
	
	
public ComposantGraphiqueMonstre(String id, IEntity e) throws SlickException {
		super(id,e);
sprites = new SpriteSheet("res/images/zombie29x33.png",imageX,imageY);
spriteNaissance= new SpriteSheet("res/images/zombieNaissanceMort.png",imageX,imageY);


gauche=new Animation(sprites,0,2,4,2,horizontalScan,duration,autoUpdate);
droite=new Animation(sprites,0,3,4,3,horizontalScan,duration,autoUpdate);
haut=new Animation(sprites,0,1,4,1,horizontalScan,duration,autoUpdate);
bas=new Animation(sprites,0,0,4,0,horizontalScan,duration,autoUpdate);

naissance= new Animation(spriteNaissance,0,0,11,0,horizontalScan,duration,true);
mort = new Animation(spriteNaissance,11,0,0,0,horizontalScan,duration,autoUpdate);
endormi = new Animation(spriteNaissance,0,0,0,0,horizontalScan, duration, false);
		spriteCourant=bas;
		
	}
	
	@Override
	public void update(GameContainer gc, StateBasedGame sb, int delta) 
	{
		
	}
	
	
	
	
	
	@Override
	public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
		
		if (((MonstreBasique)owner).getEtatCourant() == MonstreBasique.ETAT_ENDORMI)
		{
			this.spriteCourant=this.endormi;
		}
		
		else if (((MonstreBasique)owner).getEtatCourant() == MonstreBasique.ETAT_REVEIL&&naitre)
		{
			this.naissance();
			naitre=false;
		}
		else if (((MonstreBasique)owner).getEtatCourant() == MonstreBasique.ETAT_NORMAL&&reveil)
		{
			bouger(Constants.Sud, 0);
			reveil=false;
		}
		
		spriteCourant.draw(owner.getPosition().getX()-decalageX, owner.getPosition().getY()-decalageY, imageX, imageY);
		
	}

	public void bouger(int direction, int delta) 
	{
		switch (direction)
		{
		case Constants.Nord : 
			spriteCourant=haut; 
			spriteCourant.update(delta);
			break;
		case Constants.Est : 
			spriteCourant=droite; 
			spriteCourant.update(delta);
			break;
		case Constants.Sud : 
			spriteCourant=bas; 
			spriteCourant.update(delta);
			break;
		case Constants.Ouest : 
			spriteCourant=gauche; 
			spriteCourant.update(delta);
			break;
		
		}
	}
	
	
	public void naissance()
	{
		this.spriteCourant=naissance;
		spriteCourant.start();
		spriteCourant.stopAt(11);
	}
	
	public void mort()
	{
		this.spriteCourant=mort;
		spriteCourant.start();
		spriteCourant.stopAt(11);
		
	}
	

}
